package com.itheima.manager;


import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.PageResult;
import com.itheima.common.ResultData;
import com.itheima.domain.UmsResource;
import com.itheima.service.UmsResourceService;
import com.itheima.service.UmsRoleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 后台资源表 前端控制器
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@Component
public class UmsResourceManager {

    @DubboReference
    private UmsResourceService umsResourceService;

    // 分页模糊查询后台资源
    public ResultData listByPage(Integer pageNum, Integer pageSize, Integer categoryId, String nameKeyword, String urlKeyword) {
        Page<UmsResource> listByPage = umsResourceService.listByPage(pageNum, pageSize, categoryId, nameKeyword, urlKeyword);
        return ResultData.ok(new PageResult(pageNum,pageSize,listByPage.getTotal(),listByPage.getPages(),listByPage.getRecords()),"");
    }

    // 添加后台资源
    public ResultData create(UmsResource umsResource) {
       // umsResource.setCreateTime(LocalDateTime.now());
        umsResourceService.createResource(umsResource);
        return ResultData.ok("","添加成功");
    }

    // 查询后台所有资源
    public ResultData getAll() {
        List<UmsResource> all = umsResourceService.getAll();
        return ResultData.ok(all,"");
    }

    // 根据ID删除后台资源
    public ResultData deleteResourceById(Integer id) {
        umsResourceService.deleteResourceById(id);
        return ResultData.ok("","删除成功");
    }

    // 修改后台资源
    public ResultData updateResourceById(Integer id, UmsResource umsResource) {
        umsResourceService.updateResourceById(id,umsResource);
        return ResultData.ok("","修改成功");
    }

    // 根据id获取详情资源
    public ResultData queryResourceById(Integer id) {
        UmsResource umsResource = umsResourceService.queryResourceById(id);
        return ResultData.ok(umsResource,"操作成功");
    }
}

